﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebshopPizzaRio
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private PizzaBLL pbll = new PizzaBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            pizzaoverzichtLV.DataSource = pbll.getAanbiedingen();
            pizzaoverzichtLV.DataBind();
        }

        protected void pizzaoverzichtLV_SelectedINdexChanging(object sender, ListViewSelectEventArgs e)
        {
            pizzaoverzichtLV.SelectedIndex = e.NewSelectedIndex;

            ShoppingCart cart = (ShoppingCart)Session["shoppingcart"];

            Items newpizza = cart.getNewItem();
            newpizza.PizzaNaam = pizzaoverzichtLV.SelectedDataKey.Values["naam"].ToString();
            decimal pps = decimal.Parse(pizzaoverzichtLV.SelectedDataKey.Values["aanbiedingprijs"].ToString());
            newpizza.PrijsperStuk = pps;
            newpizza.Aantal = 1;
            newpizza.PizzaID = int.Parse(pizzaoverzichtLV.SelectedDataKey.Values["pizzaid"].ToString());
            cart.AddItem(newpizza);

            ListView listviewmp;
            listviewmp = (ListView)(Master).FindControl("ListView1");
            listviewmp.DataBind();

            Label label1mp;
            label1mp = (Label)(Master).FindControl("label1");
            label1mp.Text = "Totaal bedrag: € " + cart.getTotaalBedrag();         
        }
    }
}